<?php
namespace Common\Model;
use Think\Model;
/**
 * 用户推荐关系模型
 * 
 */
class UserRefereeModel extends Model {
	/**
	 * 添加用户
	 * @param unknown $userid
	 * @param unknown $tuijianid
	 */
	public function adduser($userid,$tuijianid){
		$data['userid']=$userid;
		$data['refereeid']=$tuijianid;
		$data['distance']=1;
		$this->add($data);
		//推荐人数加1
		M('User')->where(array('id'=>$tuijianid))->setInc('referee_number');
		$userrelist=$this->where(array('userid'=>$tuijianid))->select();
		foreach ($userrelist as $v){
			$data['userid']=$userid;
			$data['refereeid']=$v['refereeid'];
			$data['distance']=$v['distance']+1;
			$this->add($data);
		}
	}
}